/**
 * Created by Freeman on 2016/8/1.
 */
import React,{Component,PropTypes} from 'react';
import '../less/text.less'
class Text extends Component{
    constructor(props,context){
        super(props,context);
        this.state = {
            text:''
        };
    }
    handleChange(e) {
        this.setState({ text: e.target.value })
    }
    inputing(e){
        const text = e.target.value.trim();
        if (e.ctrlKey && e.which === 13 && text.length) {
            this.props.actions.sendText(text);
            this.setState({ text: '' })
        }
    }
    render(){
        return (

            <div className="m-text">
                <textarea
                      placeholder="按 Ctrl + Enter 发送"
                      value={this.state.text}
                      onChange={this.handleChange.bind(this)}
                      onKeyUp={this.inputing.bind(this)}
                ></textarea>
            </div>
        )
    }
}

Text.propTypes = {
    actions:PropTypes.object.isRequired
}

export default Text